package concur;

public class TicketManager {
	int ticketCount = 0;
	public synchronized void produce() {
		if(ticketCount >= 1000) {
			System.out.println("票满仓");
			return;
		}
		ticketCount++;
		this.notify();
		System.out.println("产生一张票！！");
	}
	public synchronized  void consume() {
		if(ticketCount > 0) {
			ticketCount--;
			System.out.println("购票成功！！");
			return;
		}else {
		System.out.println("没票了，一会儿再来！！");
		try {
			this.wait();
			System.out.println("我被唤醒了");
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
		}
	}
}
